<template>
	<view class="charts-box">
		<view class="add_user" @click="addBtnFun">
			添加+
		</view>
		<view class="charts-t">
			<u-tabs @click="onTabs" :list="list4" lineWidth="30" lineColor="#f56c6c" :activeStyle="{color: '#303133',fontWeight: 'bold',}" :inactiveStyle="{color: '#606266',}" itemStyle="padding-right: 15px; height: 34px;">
			</u-tabs>
		</view>
		<view class="charts-user" v-if="index == 0">
			<view style="box-sizing: border-box;padding: 30rpx;background: #fff;">
				<u-search placeholder="请输入" @custom="searchFun" v-model="serachVal"></u-search>
			</view>
			<view class="charts-user-list">
				<fui-collapse-item :key="index" icon="arrow-down" v-for="(item,index) in users">
					<view class="fui-item__box">
						<text>用户：{{item.nickName}}</text>
					</view>
					<template v-slot:content>
						<view v-if="item.state == 1">
							<fui-input label="状态：" readonly borderTop value="正常"></fui-input>
						</view>
						<view v-if="item.state == 2">
							<fui-input label="状态：" readonly borderTop value="过期"></fui-input>
						</view>
						<view v-if="item.state == 3">
							<fui-input label="状态：" readonly value="禁用"></fui-input>
						</view>

						<view v-if="item.power == 1">
							<fui-input label="权限：" readonly value="管理员"></fui-input>
						</view>
						<view v-if="item.power == 2">
							<fui-input label="权限：" readonly value="监管人员"></fui-input>
						</view>

						<view v-if="item.power == 3">
							<fui-input label="权限：" readonly value="操作员"></fui-input>
						</view>

						<view v-if="item.phone">
							<fui-input @click="onPhone(item.phone)" label="联系方式：" readonly :value="item.phone"></fui-input>
						</view>
						<view v-if="item.phone">
							<fui-input label="用户到期时间：" readonly :value="item.userExpirationTime"></fui-input>
						</view>
						<view>
							<fui-input label="绑定单位：" readonly :value="item.unitName"></fui-input>
						</view>
						<view class="charts-user-list-son">
							<up-button @click="onShowAuthority(item)" text="修改权限"></up-button>
						</view>
						<view class="charts-user-list-son">
							<up-button @click="onShowcode(item)" text="修改密码"></up-button>
						</view>
						<view class="charts-user-list-son">

							<up-button @click="onSelectTimeSetShow(item)" text="设置用户到期时间"></up-button>
						</view>
						<view class="charts-user-list-son">
							<up-button @click="onShowStatus(item)" text="设置用户状态"></up-button>
						</view>
						<view class="charts-user-list-son">
							<up-button @click="onDelUser(item)" type="error" text="删除此用户"></up-button>
						</view>
					</template>
				</fui-collapse-item>
			</view>
		</view>
		<view class="charts-unit" v-if="index == 1">
			<view style="box-sizing: border-box;padding: 30rpx;background: #fff;">
				<u-search placeholder="请输入" @custom="searchFun" v-model="serachVal"></u-search>
			</view>
			<!-- <view>
				<fui-list-cell :highlight="false">
					<view class="fui-list__cell fui-flex__center">
						<text>类别：</text>
						<fui-dropdown-menu :isCheckbox="false" selectedColor="#FF2B2B" splitLine :options="options"
							ref="ddmTag" direction="down" @click="tagItemClick" @close="tagClose">
							<view class="fui-select fui-flex__between" @tap="tagTap">
								<text>{{tag}}</text>
								<view class="fui-filter__icon" :class="{'fui-icon__ani':tagShow}">
									<fui-icon name="turningdown" :size="32"></fui-icon>
								</view>
							</view>
						</fui-dropdown-menu>
					</view>
				</fui-list-cell>
			</view> -->
			<view v-if="unitIndex == 0">
				<fui-collapse-item :title="unitsName + item.unitName" :key="index" v-for="(item,index) in units">
					<view class="fui-item__box">
						<text>{{unitsName + item.unitName}}</text>
					</view>

					<template v-slot:content>
						<fui-input label="单位创建时间：" readonly :value="item.createTime"></fui-input>
						<fui-input label="单位经营类型：" readonly :value="item.unitType"></fui-input>
						<fui-input label="安全责任人：" readonly :value="item.safetyName"></fui-input>
						<fui-input label="责任人联系方式：" readonly :value="item.safetyPhone"></fui-input>
						<fui-input label="单位唯一标识符：" readonly :value="item.unitID"></fui-input>
						<fui-input label="所属分组：" readonly :value="item.groupID"></fui-input>
						<button class="com_btn" :id="itme?.id" open-type="share" type="primary">
							添加组员
						</button>
						<u-button @click="onUnits(item)" type="error">删除此单位</u-button>
					</template>

				</fui-collapse-item>
			</view>
			<view v-if="unitIndex == 1">
				<fui-collapse-item :title="unitsName + item.unitName" :key="index" v-for="(item,index) in units">
					<view class="fui-item__box">
						<text>{{unitsName + item.unitDistrict}}</text>
					</view>

					<template v-slot:content>
						<fui-input label="单位创建时间：" readonly :value="item.createTime"></fui-input>
						<fui-input label="单位经营类型：" readonly :value="item.unitType"></fui-input>
						<fui-input label="安全责任人：" readonly :value="item.safetyName"></fui-input>
						<fui-input label="责任人联系方式：" readonly :value="item.safetyPhone"></fui-input>
						<fui-input label="单位唯一标识符：" readonly :value="item.unitID"></fui-input>
						<u-button @click="onUnits(item)" type="error">删除此单位</u-button>
					</template>

				</fui-collapse-item>
			</view>
			<view v-if="unitIndex == 2">
				<fui-collapse-item :title="unitsName + item.unitName" :key="index" v-for="(item,index) in units">
					<view class="fui-item__box">
						<text>{{unitsName + item.createTime}}</text>
					</view>

					<template v-slot:content>
						<fui-input label="单位创建时间：" readonly :value="item.createTime"></fui-input>
						<fui-input label="单位经营类型：" readonly :value="item.unitType"></fui-input>
						<fui-input label="安全责任人：" readonly :value="item.safetyName"></fui-input>
						<fui-input label="责任人联系方式：" readonly :value="item.safetyPhone"></fui-input>
						<fui-input label="单位唯一标识符：" readonly :value="item.unitID"></fui-input>
						<u-button @click="onUnits(item)" type="error">删除此单位</u-button>
					</template>

				</fui-collapse-item>
			</view>
			<view v-if="unitIndex == 3">
				<fui-collapse-item :title="unitsName + item.unitName" :key="index" v-for="(item,index) in units">
					<view class="fui-item__box">
						<text>{{unitsName + item.unitType}}</text>
					</view>

					<template v-slot:content>
						<fui-input label="单位创建时间：" readonly :value="item.createTime"></fui-input>
						<fui-input label="单位经营类型：" readonly :value="item.unitType"></fui-input>
						<fui-input label="安全责任人：" readonly :value="item.safetyName"></fui-input>
						<fui-input label="责任人联系方式：" readonly :value="item.safetyPhone"></fui-input>
						<fui-input label="单位唯一标识符：" readonly :value="item.unitID"></fui-input>
						<u-button @click="onUnits(item)" type="error">删除此单位</u-button>
					</template>

				</fui-collapse-item>
			</view>
			<view v-if="unitIndex == 4">
				<fui-collapse-item :title="unitsName + item.unitName" :key="index" v-for="(item,index) in units">
					<view class="fui-item__box">
						<text>{{unitsName + item.safetyName}}</text>
					</view>

					<template v-slot:content>
						<fui-input label="单位创建时间：" readonly :value="item.createTime"></fui-input>
						<fui-input label="单位经营类型：" readonly :value="item.unitType"></fui-input>
						<fui-input label="安全责任人：" readonly :value="item.safetyName"></fui-input>
						<fui-input label="责任人联系方式：" readonly :value="item.safetyPhone"></fui-input>
						<fui-input label="单位唯一标识符：" readonly :value="item.unitID"></fui-input>
						<u-button @click="onUnits(item)" type="error">删除此单位</u-button>
					</template>

				</fui-collapse-item>
			</view>
		</view>
		<view v-if="index == 2">
			<fui-collapse-item icon="grid" :key="index" v-if="jiangunList.length > 0" v-for="(itme,index) in jiangunList" @change="change" @close="close" @open="open">

				<view class="fui-item__box">
					<text>监管分组名：{{itme.groupsName}}</text>
				</view>
				<template v-slot:content>
					<view :key="indexx" v-for="(i,indexx) in itme.unitList">
						<fui-input readonly :value="i.unitName" label="单位名称:" borderTop></fui-input>
						<fui-input readonly :value="itme.userName" label="组所属管理员:" borderTop></fui-input>
					</view>
					<view class="charts-user-list-son">
						<button class="com_btn" :id="itme?.id" open-type="share" type="primary">
							添加组员
						</button>
					</view>
					<!-- <view class="charts-user-list-son">
						<u-button type="primary" @click="addGroupsUnit(itme.id)">添加组员</u-button>
					</view> -->
					<view class="charts-user-list-son">
						<u-button type="error" @click="delGroupsUnit(itme.id)">删除此分组</u-button>
					</view>
				</template>

			</fui-collapse-item>
		</view>
		<view v-if="index == 3">
			<fui-collapse-item icon="grid" :key="index" v-if="groups.length > 0" v-for="(itme,index) in groups" @change="change" @close="close" @open="open">

				<view class="fui-item__box">
					<text>组名：{{itme.groupsName}}</text>
				</view>
				<template v-slot:content>
					<view :key="indexx" v-for="(i,indexx) in itme.unitList">
						<fui-input readonly :value="i.unitName" label="单位名称:" borderTop></fui-input>
						<fui-input readonly :value="itme.userName" label="组所属管理员:" borderTop></fui-input>
					</view>
					<br />
					<view class="charts-user-list-son">
						<u-button type="primary" @click="addGroupsUnit(itme.id)">添加单位</u-button>
					</view>

					<view class="charts-user-list-son">
						<u-button type="error" @click="delGroupsUnit(itme.id)">删除此分组</u-button>
					</view>
				</template>

			</fui-collapse-item>
		</view>
		<view v-if="index == 4">
			<view class="u-page__item">
				<fui-collapse-item v-for="(item,index) in devices" :key="index" :title="'设备编号：' +  item.deviceNumber ">
					<view class="fui-item__box">
						<text>设备编号：{{item.deviceNumber}}</text>
					</view>
					<template v-slot:content>
						<fui-input readonly :value="item.createTime" label="创建时间:" borderTop></fui-input>
						<fui-input readonly :value="item.type" label="类型:" borderTop></fui-input>
						<fui-input readonly :value="item.faceSpan + '分钟'" label="人脸检测间隔时间:" borderTop></fui-input>
						<fui-input readonly color="#465CFF" v-if="item.enable == 1" value="启用" label="状态:" borderTop></fui-input>
						<fui-input readonly color="#FF2B2B" v-if="item.enable != 1" value="禁用" label="状态:" borderTop></fui-input>
						<fui-input readonly color="#09BE4F" v-if="item.states != 1" value="空闲中" label="作业状态:" borderTop></fui-input>
						<fui-input readonly color="#6831FF" v-if="item.states == 1" value="作业中" label="作业状态:" borderTop></fui-input>
						<view class="charts-user-list-son">
							<up-button @click="onShowFileMan(item)" text="添加操作员"></up-button>
						</view>
						<view class="charts-user-list-son">
							<up-button @click="toFileMan(item)" text="查看操作员"></up-button>
						</view>
						<view class="charts-user-list-son">
							<up-button @click="onDeviceOpsShow(item)" text="更多"></up-button>
						</view>

					</template>
				</fui-collapse-item>
			</view>
		</view>
		<view v-if="loading" class="loading">加载中...</view>
		<view v-if="noMore" class="no-more">已经到底啦~</view>
		<u-datetime-picker title="选择用户过期时间" :show="showSelectTimeSet" @cancel="showSelectTimeSet =!showSelectTimeSet" @confirm="onSelectTimeSet" :min-date="minDate" mode="date"></u-datetime-picker>
		<u-datetime-picker title="选择用户过期时间" :show="showSelectTime" @cancel="showSelectTime =!showSelectTime" @confirm="onSelectTime" :min-date="minDate" mode="date"></u-datetime-picker>
		<u-modal :show="showUserAdd" @cancel="showUserAdd = !showUserAdd" @confirm="onUserAdd" showCancelButton title="添加用户">
			<view class="slot-content">
				<view class="slot-content-user-ops">
					<fui-input maxlength="20" v-model="userAdd.nickName" label="用户名:" borderTop placeholder="请输入用户名"></fui-input>
				</view>
				<view class="slot-content-user-ops">
					<fui-input type="number" maxlength="11" v-model="userAdd.phone" label="手机号:" borderTop placeholder="请输入手机号"></fui-input>
				</view>
				<view class="slot-content-user-ops">
					<fui-input maxlength="20" password v-model="userAdd.pwd" label="密码:" borderTop placeholder="请输入密码"></fui-input>
				</view>
				<view class="slot-content-user-ops">
					<fui-input maxlength="20" readonly @click="showUnit =!showUnit" v-model="userAdd.unit" label="绑定单位:" borderTop placeholder="请选择单位"></fui-input>
				</view>
				<view class="slot-content-user-ops">
					<fui-input v-model="userAdd.data" @click="showSelectTime = !showSelectTime" readonly label="用户过期时间:" borderTop placeholder="请选择用户到期时间"></fui-input>
				</view>
			</view>
		</u-modal>
		<u-picker title="选择状态" @cancel="showStatus = !showStatus" @confirm="onStatus" :show="showStatus" :columns="Status"></u-picker>
		<u-popup :show="modifyPwdFlag" :round="10" mode="center" @close="close" @open="open" style="width: 90%; margin: auto; display: flex; justify-content: space-between; align-items: center;">
			<view class="pwdModify">
				<template>
					<u-form :model="changeForm.newpwd" ref="changeFormRules">
						<u-form-item label="密码" prop="newpwd">
							<u-input v-model="changeForm.newpwd" placeholder="请输入新的密码" border="bottom" />
						</u-form-item>
						<u-form-item>
							<view class="display_flex">
								<u-button @click="closeNewPwd">取消</u-button>
								<u-button @click="updateNewPwd">提交</u-button>
							</view>
						</u-form-item>
					</u-form>
				</template>
			</view>
		</u-popup>
		<u-picker title="选择权限" @cancel="showAuthority = !showAuthority" @confirm="onAuthority" :show="showAuthority" :columns="authority"></u-picker>
		<u-picker title="选择填写工作记录时间" @cancel="showTime = !showTime" @confirm="onTines" :show="showTime" :columns="tiems"></u-picker>
		<u-picker title="选择绑定单位" @cancel="showUnit = !showUnit" @confirm="onUnit" :show="showUnit" :columns="unitNames"></u-picker>
		<u-picker title="选择绑定单位" @cancel="showGroutUnit = !showGroutUnit" @confirm="onAddGroutUnit" :show="showGroutUnit" :columns="unitNames"></u-picker>
		<view>
			<up-action-sheet @select="onDeviceOps" @close="showDeviceOps=!showDeviceOps" :round="18" :actions="deviceList" title="设置" :show="showDeviceOps"></up-action-sheet>
		</view>
		<view>
			<u-modal :show="showUnitsAdd" @cancel="showUnitsAdd = !showUnitsAdd" @confirm="onUnitsAdd" showCancelButton title="添加单位">
				<view class="slot-content">
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" required v-model="unitsAdd.unitName" label="单位名称:" borderTop placeholder="请输入"></fui-input>
					</view>

					<view class="slot-content-user-ops">
						<fui-input maxlength="20" required v-model="unitsAdd.safetyName" label="安全责任人:" borderTop placeholder="请输入"></fui-input>
					</view>

					<view class="slot-content-user-ops">
						<fui-input maxlength="11" number required v-model="unitsAdd.safetyPhone" label="责任人联系方式:" borderTop placeholder="请输入"></fui-input>
					</view>

					<view class="slot-content-user-ops">
						<fui-input maxlength="30" :padding="['20rpx','32rpx']" required v-model="unitsAdd.unitAddress" label="单位详细地址:" borderTop placeholder="请输入">
							<!-- <fui-icon size="30" @click="onSelectLocat" color="#409EFF"  name="location"></fui-icon> -->
						</fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" readonly required v-model="unitsAdd.unitDistrict" label="所属行政区域:" borderTop placeholder="请选择" @click="this.showDistrict = !this.showDistrict"></fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" readonly required v-model="unitsAdd.unitNature" label="企业类型:" borderTop placeholder="请选择" @click="this.showNnitNature = !this.showNnitNature"></fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" v-if="unitsAdd.unitNature" readonly required v-model="unitsAdd.groupName" label="选择分组:" borderTop placeholder="请选择" @click="this.showgroupSelect = !this.showgroupSelect"></fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" readonly required v-model="unitsAdd.unitType" label="单位经营类型:" borderTop placeholder="请选择" @click="this.showUnitType =!this.showUnitType"></fui-input>
					</view>
				</view>
			</u-modal>
		</view>
		<view>
			<u-modal :show="showUnitsAdd_jianguan" @cancel="showUnitsAdd_jianguan = !showUnitsAdd_jianguan" @confirm="onUnitsAdd_jianguan" showCancelButton title="添加监管分组">
				<view class="slot-content">

					<view class="slot-content-user-ops">
						<fui-input maxlength="20" readonly required v-model="contro_group_list.unitArea" label="所属行政区域:" borderTop placeholder="请选择" @click="this.showDistrict = !this.showDistrict"></fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" required v-model="contro_group_list.control_group" label="监管分组名:" borderTop placeholder="请输入"></fui-input>
					</view>

				</view>
			</u-modal>
		</view>
		<view>
			<qianziyu-select :show="showNnitNature" type="radio" name="label" :showSearch="false" :dataLists="unitNatureList" @cancel="this.showNnitNature=false" @submit="onunitNature" </qianziyu-select>
		</view>
		<view>
			<qianziyu-select :show="showgroupSelect" type="radio" name="groupsName" :dataLists="jiangunListAll" @cancel="this.showgroupSelect=false" @submit="onGroupSubmit" </qianziyu-select>
				<!-- @search="selectSearch" -->
		</view>
		<view>
			<u-picker :show="showUnitType" @confirm="onUnitType" @cancel="this.showUnitType =!this.showUnitType" title="单位经营类型" :columns="unitTypeColumns"></u-picker>
		</view>
		<view>
			<cityPicker :column="column" :default-value="defaultValue" :mask-close-able="maskCloseAble" @confirm="oSetCity" @cancel="this.showDistrict = !this.showDistrict" :visible="showDistrict" />
		</view>
		<view>
			<u-modal :showCancelButton="true" @confirm="onAddGroup" @cancel="showGroup = !showGroup" :show="showGroup" title="新建分组">
				<view class="slot-content">
					<fui-input label="分组名" v-model="groupName" borderTop placeholder="请输入分组名"></fui-input>
					<fui-input label="监管人员" v-model="groupUser" borderTop placeholder="请输入监管人员账号"></fui-input>
				</view>
			</u-modal>
		</view>
		<view>
			<u-modal :showCancelButton="true" @confirm="addGroupsAdmin" @cancel="showGroupAddAdmin = !showGroupAddAdmin" :show="showGroupAddAdmin" title="监管人员">
				<view class="slot-content">
					<fui-input label="监管人员" v-model="groupUser" borderTop placeholder="请输入监管人员账号"></fui-input>
				</view>
			</u-modal>
		</view>
		<view>
			<u-modal :showCancelButton="true" @confirm="addGroupDistribution" @cancel="showGroupDistribution = !showGroupDistribution" :show="showGroupDistribution" title="设置监管群组">
				<view class="slot-content">
					<fui-input label="监管人员" v-model="groupUser" borderTop placeholder="请输入监管人员账号"></fui-input>
					<fui-input label="分组" :key="index" v-for="(item,index) in inputGroups" :value="item" borderTop placeholder="请选择"></fui-input>
					<up-button @click="showgroupNamesDate = !showgroupNamesDate" type="primary" text="选择分组"></up-button>
				</view>

			</u-modal>
		</view>
		<view>
			<u-picker @confirm="onGroupNamesDate" @cancel="showgroupNamesDate = !showgroupNamesDate" :show="showgroupNamesDate" :columns="groupNamesDate"></u-picker>
		</view>
		<view>
			<u-popup :round="10" :show="showGroupPop" @close="showGroupPop = !showGroupPop" @open="open">
				<view style="width: 90%; margin: auto; display: flex; justify-content: space-between; align-items: center;">
					<view style="width: 80rpx;">
						<up-button size="mini" @click="showGroupPop = !showGroupPop" text="取消"></up-button>
					</view>
					<view style="width: 70%;">
						<fui-input v-model="groupUser" inputBorder borderTop placeholder="请输入监管人员账号"></fui-input>
					</view>
					<view style="width: 80rpx;">
						<up-button @click="addGroupDistribution" size="mini" text="确定"></up-button>
					</view>
				</view>
				<view class="pop-addgroups">
					<jp-virtual-list :pageSizes="groupNamesDate.length" code="id" class="h100" :refresher="false" @scrolltoupper="scrolltoupper" @refresher="refresher" :data="groupNamesDate" ref="search">
						<template v-slot="{ list  }">
							<view style="width: 80%; margin: auto;">
								<u-checkbox-group :borderBottom="true" iconPlacement="right" placement="column" v-model="checkboxValue1" @change="checkboxChange">
									<u-checkbox :key="item.id" :id="item.id" :ref="item.id" :customStyle="{marginBottom: '8px'}" v-for="(item, index) in list " :label="item.name" :name="item.name" :disabled="item.disabled">
									</u-checkbox>
								</u-checkbox-group>
							</view>
						</template>
					</jp-virtual-list>
				</view>
			</u-popup>
		</view>
		<view>
			<up-modal @confirm="onAddDevice" :showCancelButton="true" @cancel="showAddDevice =!showAddDevice" @close="showAddDevice =!showAddDevice" :show="showAddDevice" title="添加设备">
				<view class="slot-content">
					<fui-input clearable type="number" maxlength="11" text-align="right" v-model="addDevice.number" label="设备编号" borderTop placeholder="请输入设备编号"></fui-input>
					<fui-input text-align="right" readonly @click="showdeviceTypes =!showdeviceTypes" v-model="addDevice.type" label="设备类型" borderTop placeholder="请选择设备类型"></fui-input>
					<fui-input text-align="right" readonly @click="showdeviceEnab =!showdeviceEnab" v-model="addDevice.enable.label" label="是否启用" borderTop placeholder="请选择"></fui-input>
					<fui-input text-align="right" readonly @click="showdeviceTime=!showdeviceTime" v-model="addDevice.faceSpan" label="人脸检测间隔时间" borderTop placeholder="请选择">
						<text>分钟</text>
					</fui-input>
				</view>
			</up-modal>
			<!-- showAddFileMan -->
			<up-modal @confirm="onAddFileMan" :showCancelButton="true" @cancel="showAddFileMan =!showAddFileMan" @close="showAddFileMan =!showAddFileMan" :show="showAddFileMan" title="添加操作员">
				<view class="slot-content">
					<fui-input clearable maxlength="20" text-align="right" v-model="fileManAccount" label="账号" borderTop placeholder="请输入操作员账号"></fui-input>

				</view>
			</up-modal>
		</view>
		<view>
			<up-picker title="选择类型" @confirm="onSelectDevType" @cancel="showdeviceTypes =!showdeviceTypes" @close="showdeviceTypes =!showdeviceTypes" :show="showdeviceTypes" :columns="deviceTypes"></up-picker>
			<up-picker title="选择状态" @confirm="onSelectDevEnab" @cancel="showdeviceEnab =!showdeviceEnab" :show="showdeviceEnab" :columns="deviceEnabs"></up-picker>
			<up-picker title="选择时间" @confirm="onSelectDevTimes" @cancel="showdeviceTime =!showdeviceTime" :show="showdeviceTime" :columns="deviceTimes"></up-picker>
			<up-picker title="选择时间" @confirm="onSelectDevTimes1" @cancel="showdeviceTime1 =!showdeviceTime1" :show="showdeviceTime1" :columns="deviceTimes"></up-picker>
		</view>
	</view>
</template>

<script>
	import {
		BASE_IP
	} from '@/common/http/url.js'
	import cityPicker from '@/uni_modules/piaoyi-cityPicker/components/piaoyi-cityPicker/piaoyi-cityPicker'
	import {
		BASE_API
	} from '@/common/http/url.js'
	export default {
		data() {
			return {
				newpwd: "",
				modifyPwdFlag: false,
				fileManAccount: "",
				showAddFileMan: false,
				showdeviceTime1: false,
				deviceList: [{
						id: 0,
						name: '启用'
					}, {
						id: 1,
						name: "开始作业"
					}, {
						id: 2,
						name: "人脸识别间隔"
					}, {
						id: 3,
						name: "禁用",
						color: "#fa3534"
					},
					{
						id: 4,
						name: "停止作业",
						color: "#fa3534"
					},
					{
						id: 5,
						name: "删除此设备",
						color: "#fa3534"
					}
				],
				showDeviceOps: false,
				showdeviceTime: false,
				deviceTimes: [
					[
						10, 20, 30, 60, 90, 120, 150, 180
					]
				],
				showdeviceEnab: false,
				deviceEnabs: [
					['禁用', '启用']
				],
				showdeviceTypes: false,
				showAddDevice: false,
				deviceTypes: [
					[
						"报警", "避雷", "电器", "定位器", "摄像头", "水压表", "天然气", "消防", "烟感", "智慧屏"
					]
				],
				addDevice: {
					number: "",
					type: "",
					enable: {
						value: 1,
						label: "启用"
					},
					faceSpan: "" //人脸识别到期时间
				},
				showSelectTimeSet: false,
				list4: [{
						name: '用户管理'
					}, {
						name: '企业分组',
					}, {
						name: '监管分组',
					}, {
						name: '管理员分组',
					}
					// , {
					// 	name: '设备管理',
					// },
				],
				index: 0,
				authority: [
					['管理员', '监管人员', '操作员']
				],
				showAuthority: false,
				showTime: false,
				tiems: [
					['1', '7', '14', '30']
				],
				users: "",
				title: "用户名：",
				userItme: "",
				Status: [
					['正常', '过期', '禁用']
				],
				showStatus: false,
				showUserAdd: false,
				userAdd: {
					name: "",
					pwd: "",
					data: "",
					unit: "",
					nickName: "",
					phone: ""
				},
				showSelectTime: false,
				minDate: new Date(),
				units: [],
				unitNames: "",
				showUnit: false,
				unitsName: "单位名称：",
				unitsAdd: {
					"landPlanningType": "",
					"safetyName": "",
					"safetyPhone": "",
					"unitAbbreviation": "",
					"unitAddress": "",
					"unitArea": "",
					"unitName": "",
					"unitType": "",
					"unitDistrict": "",
					"unitNature": "",
					"unitNatureId": "",
					"groupName": null,
					"groupID": null
				},
				contro_group_list: {

					"unitArea": "",
					"control_group": "",

				},
				showUnitsAdd: false,
				showUnitsAdd_jianguan: false,
				unitTypeColumns: [
					['甲乙类厂房', '丙类厂房', '丁戊类厂房', '甲乙类仓库', '丙类仓库',
						'丁戊类仓库', '办公', '普通商业', '娱乐类商业', '体育场馆', '餐饮就业', '酒店商业', '公寓商业'
					]
				],
				showgroupSelect: false,
				showNnitNature: false,
				showUnitType: false,
				showDistrict: false,
				province: "",
				city: "",
				area: "",
				defaultValue: "",
				visible: true,
				maskCloseAble: true,
				addressList: [],
				unitsops: [{
					name: '单位',
				}, {
					name: '行政区域',
				}, {
					name: '创建时间'
				}, {
					name: '经营类型'
				}, {
					name: '责任人'
				}],
				options: ['单位', '行政区域', '创建时间', '经营类型', '责任人'],
				tag: '单位',
				tagShow: false,
				unitIndex: 0,
				showGroup: false,
				groupName: "",
				groupUser: "",
				groups: "",
				showGroutUnit: false,
				unitid: 0,
				groupitme: "",
				showGroupAddAdmin: false,
				showAddAdminGroups: false,
				groupNames: [],
				groupNamesDate: [],
				showGroupDistribution: false,
				inputGroups: [],
				showgroupNamesDate: false,
				showGroupPop: false,
				checkboxValue1: [],
				checkboxList1: [{
					name: '苹果',
					disabled: false
				}],
				key: '',
				userItem: "",
				devices: [],
				deviceItem: "",
				changeForm: {
					newpwd: ""
				},
				currentPage: 1,
				pageSize: 15,
				serachVal: null,
				changeFormRules: {
					'changeForm.newpwd': {
						type: 'string',
						required: true,
						max: 8,
						min: 8,
						message: '请输入密码',
						trigger: ['blur', 'change']
					}
				},
				noMore: false,
				loading: false,
				jiangunList: [],
				jiangunListAll: [],
				adminList: [],
				adminListAll: [],
				unitNatureList: [
					// {
					// 	label:"企业类 ",
					// 	value:"1000"
					// },
					{
						label: "监管类",
						value: "2000"
					},
					{
						label: "管理员类",
						value: "3000"
					}
				]
			}
		},

		components: {
			cityPicker
		},
		onShareAppMessage(res) {
			console.log(res)
			let title = ""
			let path = ""
			if (this.index == 1) {
				title = this.user.nickName + '邀请您加入他的企业！'
				path = '/pagesMine/wxLogin/wxLogin?power=3&unitGroupId=' + res.target.id
			}
			if (this.index == 2) {
				title = this.user.nickName + '邀请您加入他的监管班组！'
				path = '/pagesMine/wxLogin/wxLogin?power=2&unitGroupId=' + res.target.id
			}
			return {
				debug: true,
				title: title,
				path: path,
				imageUrl: 'https://mp-bfea0f33-0deb-44c8-86f2-196dd6ca37a5.cdn.bspapp.com/test/head.jpg',
				success(res) {
					console.log('分享成功', res);
				},
				fail(err) {
					console.log('分享失败', err);
				}
			}
		},
		onLoad() {
			this.user = uni.getStorageSync("user")
			this.getUsers()
			// this.getUnit()
			this.getAllUnit();
			this.calculateFutureDate()
			this.getSuperviseAllGroup()
			this.getAdminAllGroup()
		},
		onShow() {

		},
		onReachBottom() {
			// 滚动到底部触发
			if (!this.noMore && !this.loading) {
				this.currentPage++
				this.loadData()
			}
		},
		methods: {
			//管理员分组查询分页接口
			getAdminGroup() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/group/page/admin"
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					data: {
						"currentPage": this.currentPage,
						"pageSize": this.pageSize,
						"unitGroupName": ""
					},
					url: url,
					success: (res) => {
						console.log("管理员分组查询接口：", res.data.records)
						if (res.statusCode == 200) {
							if (res.data.records.length === 0) {
								this.noMore = true
								return
							}
							this.adminList = [...this.adminList, ...res.data.records]

							if (res.data.records.length < this.pageSize) {
								this.noMore = true
							}
						}
					}
				})
			},
			// 管理员所有数据查询接口
			getAdminAllGroup() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/group/page/admin"
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					data: {
						"currentPage": 1,
						"pageSize": 999,
						"unitGroupName": ""
					},
					url: url,
					success: (res) => {
						console.log("管理员分组查询接口：", res.data.records)
						if (res.statusCode == 200) {
							this.adminListAll = res.data.records
						}
					}
				})
			},
			// 监管分组查询分页接口
			getSuperviseGroup() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/group/page/supervise"
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					data: {
						"currentPage": this.currentPage,
						"pageSize": this.pageSize,
						"unitGroupName": ""
					},
					url: url,
					success: (res) => {
						console.log("监管分组：", res.data)
						if (res.statusCode == 200) {
							if (res.data.records.length === 0) {
								this.noMore = true
								return
							}
							this.jiangunList = [...this.jiangunList, ...res.data.records]

							if (res.data.records.length < this.pageSize) {
								this.noMore = true
							}
						}
					}
				})
			},
			// 监管分组所有数据查询接口
			getSuperviseAllGroup() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/group/page/supervise"
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					data: {
						"currentPage": 1,
						"pageSize": 999,
					},
					url: url,
					success: (res) => {
						console.log("监管分组查询接口：", res.data.records)
						if (res.statusCode == 200) {
							this.jiangunListAll = res.data.records
						}
					}
				})
			},
			resetPage() {
				this.users = []
				this.units = []
				this.jiangunList = []
				this.serachVal = ''
				this.currentPage = 1
				this.noMore = false
				this.loading = false
			},
			createPage() {
				this.serachVal = ''
				this.currentPage = 1
				this.noMore = false
				this.loading = false
			},
			loadData() {
				// this.resetPage();
				if (this.index == 0) {
					this.getUsers()
				} else if (this.index == 1) {
					this.getUnit()
				} else if (this.index == 2) {
					this.getSuperviseGroup()
				} else if (this.index == 2) {
					this.getAdminGroup()
				}
			},
			searchFun(e) {
				if (this.index == 0) {
					this.users = []
					this.getUsersSearch()
				} else if (this.index == 1) {
					this.units = [];
					this.getUnit()
				}
			},
			open() {
				console.log("open")
			},
			close() {
				console.log("close")
			},
			// 新增弹出方法
			addBtnFun() {
				if (this.index == 0) {
					this.showUserAdd = !this.showUserAdd
				} else if (this.index == 1) {
					this.showUnitsAdd = !this.showUnitsAdd
				} else if (this.index == 2) {
					this.showUnitsAdd_jianguan = !this.showUnitsAdd_jianguan
				} else if (this.index == 3) {
					this.showGroup = !this.showGroup
				} else if (this.index == 4) {
					this.showAddDevice = !this.showAddDevice
				}
			},
			calculateFutureDate() {
				const today = new Date()
				const nextYear = new Date(today)
				nextYear.setFullYear(today.getFullYear() + 1)
				const year = nextYear.getFullYear()
				const month = String(nextYear.getMonth() + 1).padStart(2, '0')
				const day = String(nextYear.getDate()).padStart(2, '0')
				this.userAdd.data = `${year}-${month}-${day}`
			},
			toFileMan(res) {
				console.log(res)
				uni.navigateTo({
					url: "/pagesMine/admin/fileMan/fileMan?id=" + res.id
				})
			},
			onAddFileMan() {
				if (this.fileManAccount == "") {
					uni.showToast({
						title: "请输入账号",
						icon: "error"
					})
					return
				}

				this.showAddFileMan = !this.showAddFileMan
				let url = BASE_IP + "pc/device/add/man/" + this.fileManAccount + "/" + this.deviceItem.id
				console.log(url)
				let user = uni.getStorageSync("user")
				uni.request({
					header: {
						"Authorization": user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: url,
					method: "POST",
					success: (res) => {
						console.log(res)
						if (res.statusCode == 200) {
							if (res.data.code != 1) {
								uni.showModal({
									title: "提示",
									content: res.data.msg,
									showCancel: false
								})
								return
							} else {
								uni.showToast({
									title: "添加成功",
									icon: "success"
								})
							}
						} else {

							uni.showToast({
								title: "添加失败",
								icon: "error"
							})
						}
					},
					fail: (res) => {
						uni.showToast({
							title: "添加失败",
							icon: "error"
						})
					}
				})
				this.fileManAccount = ""
			},
			onShowFileMan(res) {
				this.deviceItem = res
				this.showAddFileMan = !this.showAddFileMan
			},
			onSelectDevTimes1(res) {
				console.log(res)
				this.showdeviceTime1 = !this.showdeviceTime1
				let url = BASE_IP + "pc/device/up/2/" + res.value[0] + "/" + this.deviceItem.id
				let user = uni.getStorageSync("user")
				console.log(url)
				uni.request({
					header: {
						"Authorization": user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: url,
					method: "POST",
					success: (res) => {
						console.log(res)
						if (res.statusCode == 200) {
							if (res.data.code == 1) {
								uni.showToast({
									title: res.data.data,
									icon: "success"
								})
								this.queryDevices()
							} else {
								uni.showToast({
									title: "操作失败",
									icon: "error"
								})
							}
						} else {
							uni.showToast({
								title: "操作失败",
								icon: "error"
							})
						}
					},
					fail: (res) => {
						uni.showToast({
							title: "操作失败",
							icon: "error"
						})
					}
				})

			},
			onDeviceOpsShow(res) {
				console.log(res)
				this.deviceItem = res
				this.showDeviceOps = !this.showDeviceOps
			},
			onDeviceOps(res) {
				let user = uni.getStorageSync("user")
				console.log(res)
				let url;
				if (res.id == 0) {
					url = BASE_IP + "pc/device/up/" + res.id + "/0/" + this.deviceItem.id
				}
				if (res.id == 1) {
					url = BASE_IP + "pc/device/up/" + res.id + "/1/" + this.deviceItem.id
				}
				if (res.id == 2) {
					// url = BASE_IP + "pc/device/up/"+res.id+"/2/" + this.deviceItem.id
					this.showdeviceTime1 = !this.showdeviceTime1
				}
				if (res.id == 3) {
					url = BASE_IP + "pc/device/up/" + res.id + "/3/" + this.deviceItem.id
				}
				if (res.id == 4) {
					url = BASE_IP + "pc/device/up/" + res.id + "/4/" + this.deviceItem.id
				}
				if (res.id == 5) {
					uni.showModal({
						title: "提示",
						content: "您确定删除此设备吗？",
						success: (res) => {
							if (res.confirm) {
								let url = BASE_IP + "pc/device/up/5/5/" + this.deviceItem.id
								uni.request({
									header: {
										"Authorization": user.token,
										'Content-Type': 'application/x-www-form-urlencoded'
									},
									url: url,
									method: "POST",
									success: (res) => {
										console.log(res)
										if (res.statusCode == 200) {
											if (res.data.code == 1) {
												uni.showToast({
													title: "删除成功",
													icon: "success"
												})
												this.queryDevices()
											} else {
												uni.showToast({
													title: "操作失败",
													icon: "error"
												})
											}
										} else {
											uni.showToast({
												title: "操作失败",
												icon: "error"
											})
										}
									},
									fail: (res) => {
										uni.showToast({
											title: "操作失败",
											icon: "error"
										})
									}
								})

							} else {
								return
							}
						}
					})
				}
				console.log(url)

				uni.request({
					header: {
						"Authorization": user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: url,
					method: "POST",
					success: (res) => {
						console.log(res)
						if (res.statusCode == 200) {
							if (res.data.code == 1) {
								uni.showToast({
									title: res.data.data,
									icon: "success"
								})
								this.queryDevices()
							} else {
								uni.showToast({
									title: "操作失败",
									icon: "error"
								})
							}
						} else {
							uni.showToast({
								title: "操作失败",
								icon: "error"
							})
						}
					},
					fail: (res) => {
						uni.showToast({
							title: "操作失败",
							icon: "error"
						})
					}
				})

			},
			queryDevices() {
				let url = BASE_IP + "pc/device/get/unit"
				let user = uni.getStorageSync("user")
				uni.request({
					header: {
						"Authorization": user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: url,
					success: (res) => {
						console.log(res)
						if (res.statusCode == 200) {
							if (res.data.code == 0) {
								this.devices = []
								return
							}
							if (res.data.code == 1) {
								this.devices = []
								let data_json = JSON.parse(res.data.data)
								for (let index in data_json) {
									this.devices.push(JSON.parse(data_json[index]))
								}
							}
						}
					}
				})
			},
			onAddDevice() {
				console.log(this.addDevice)
				if (this.addDevice.number == "") {
					uni.showToast({
						title: "设备号为空",
						icon: "error"
					})
					return
				}
				if (this.addDevice.type == "") {
					uni.showToast({
						title: "类型为空",
						icon: "error"

					})
					return
				}

				if (this.addDevice.faceSpan == "") {
					uni.showToast({
						title: "时间为空",
						icon: "error"

					})
					return
				}
				let url = BASE_IP + "pc/device/save/" + this.addDevice.number + "/" + this.addDevice.type + "/" + this
					.addDevice.enable.value + "/" + this.addDevice.faceSpan
				let user = uni.getStorageSync("user")
				uni.request({
					header: {
						"Authorization": user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: url,
					method: "POST",
					success: (res) => {
						console.log(res)
						if (res.statusCode == 200) {
							if (res.data.code == 1) {
								uni.showToast({
									icon: "success",
									title: res.data.data
								})
								this.addDevice.enable.label = "启用"
								this.addDevice.enable.value = 1
								this.addDevice.faceSpan = ""
								this.addDevice.number = ""
								this.addDevice.type = ""
								this.queryDevices()
							} else {
								uni.showToast({
									icon: "error",
									title: res.data.msg
								})
							}
						} else {
							uni.showToast({
								icon: "error",
								title: "添加失败"
							})
						}
					},
					fail: (res) => {
						uni.showToast({
							icon: "error",
							title: "添加失败"
						})
					}
				})

				this.showAddDevice = !this.showAddDevice

			},
			onSelectDevTimes(res) {
				console.log(res)
				this.addDevice.faceSpan = res.value[0]
				this.showdeviceTime = !this.showdeviceTime
			},
			onSelectDevEnab(res) {
				console.log(res)
				this.addDevice.enable.label = res.value[0]
				this.addDevice.enable.value = res.indexs[0]
				this.showdeviceEnab = !this.showdeviceEnab
			},
			onSelectDevType(res) {
				console.log(res)
				this.addDevice.type = res.value[0]
				this.showdeviceTypes = !this.showdeviceTypes
			},
			validateInput() {
				const regex = /^[a-zA-Z0-9]{6,20}$/; // 验证规则：6-20位字母和数字
				if (!regex.test(this.userAdd.name)) {
					uni.showModal({
						title: "提示",
						content: "账号必须为6-20位的字母和数字组合",
						showCancel: false
					});
					this.userAdd.name = ''; // 清空无效输入
				}
			},
			onSelectTimeSetShow(item) {
				this.userItem = item
				this.showSelectTimeSet = !this.showSelectTimeSet
			},
			onSelectTimeSet(res) {
				const dateValue = res.value
				const formattedDate = new Date(dateValue).toISOString().split("T")[0];
				console.log(formattedDate)
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/user/update/extime/" + this.userItem.uuid + "/" + formattedDate
				uni.request({
					header: {
						"Authorization": user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: url,
					method: "POST",
					success: (res) => {
						console.log(res)
						if (res.statusCode == 200) {
							if (res.data.code == 1) {
								uni.showToast({
									title: "更新成功",
									icon: "success"
								})
								this.getUsers()
							} else {
								uni.showToast({
									title: res.data.msg,
									icon: "error"
								})
							}
							return
						}
						uni.showToast({
							title: "服务器出现问题",
							icon: "error"
						})
					}
				})


				this.showSelectTimeSet = !this.showSelectTimeSet
			},
			onPhone(res) {
				console.log(res)
				uni.makePhoneCall({
					phoneNumber: res,
					success: (res) => {
						console.log(res)
					}
				})
			},
			toAssign() {
				this.$refs.search.toAssign('Item999', this)
			},
			toAssign1() {
				this.$refs.search.toAssign('Item100', this)
			},
			toAssign2() {
				this.$refs.search.toAssign('Item0', this)
			},
			scrolltoupper() {
				const data = []
				for (let i = 0; i < 30; i++) {
					data.push({
						name: `Itemc ${i}`,
						index: i,
						id: `Itemc${i}${(Math.floor(Math.random() * 100)+100)}`,
						height: (Math.floor(Math.random() * 100) + 100)
					})
				}
				setTimeout(() => {
					// 告诉组件我需要添加该数据
					this.$refs.search.addPage(data)
				}, 1000)
			},
			refresher() {
				const data = []
				for (let i = 0; i < 10000; i++) {
					data.push({
						name: `Item ${i}`,
						index: i,
						id: `Item${i}`,
						height: (Math.floor(Math.random() * 100) + 100)
					})
				}
				setTimeout(() => {
					this.listx = data
					// 告诉组件刷新成功了
					this.$refs.search.refreshers()
				}, 2000)
			},
			checkboxChange(n) {
				console.log('change', n);
				this.inputGroups = n
			},
			addGroupDistribution() {
				// console.log(res)
				if (this.groupUser == "") {
					uni.showToast({
						title: "监管人员未添加",
						icon: "error"
					})
					return
				}
				if (this.inputGroups.length < 1) {
					uni.showToast({
						title: "请分组",
						icon: "error"
					})
					return
				}
				// const uniqueGroups = [...new Set(this.inputGroups)];
				// this.inputGroups = uniqueGroups

				console.log(this.inputGroups)
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/group/update"
				console.log(url)
				uni.request({
					header: {
						"Authorization": user.token
					},
					url: url,
					dataType: 'json',
					data: {
						name: this.groupUser,
						groups: this.inputGroups
					},
					method: "POST",
					success: (res) => {
						console.log(res)
						if (res.statusCode == 500) {
							uni.showModal({
								title: "提示",
								content: "此监管账号不存在",
								showCancel: false,
								success: () => {

								}
							})
							return
						}
						if (res.statusCode == 200) {
							uni.showToast({
								title: "添加成功",
								icon: "success"
							})
							setTimeout((r) => {
								this.getGroups()
							}, 500)
							setTimeout((r) => {
								this.getGroups()
							}, 800)
						}
					}
				})
				this.showGroupPop = !this.showGroupPop
			},
			onGroupNamesDate(res) {
				let v = res.value[0]
				let temps = this.inputGroups
				for (let i in temps) {
					if (temps[i] == v) {
						return
					}
				}
				this.inputGroups.push(v)
				this.showgroupNamesDate = !this.showgroupNamesDate
			},
			onShowGroupDistribution() {
				this.inputGroups = []
				this.groupUser = ""

				// this.showGroupDistribution = !this.showGroupDistribution
				this.showGroupPop = !this.showGroupPop
			},
			addGroupsAdmin(res) {
				console.log(this.groupitme)
				this.showGroupAddAdmin = !this.showGroupAddAdmin
			},
			addGroupsAdmins(item) {
				this.groupitme = item
				this.groupUser = ""
				this.showGroupAddAdmin = !this.showGroupAddAdmin
			},
			delGroupsUnit(id) {
				uni.showModal({
					title: "提示",
					content: "您确定要删除此分组吗？",
					success: (r) => {
						if (r.confirm) {
							let url = BASE_IP + "pc/group/deleteById/" + id
							let user = uni.getStorageSync("user")
							uni.request({
								header: {
									"Authorization": user.token
								},
								url: url,
								method: "DELETE",
								success: (res) => {
									if (res.statusCode == 500) {}

									if (res.statusCode == 200) {
										uni.showToast({
											title: "删除成功",
											icon: "success"
										})
										setTimeout((r) => {
											this.getGroups()
										}, 500)
										setTimeout((r) => {
											this.getGroups()
										}, 800)
									}
								}
							})
						}
					}
				})
			},
			onAddGroutUnit(res) {
				let v = res.value[0]
				let url = BASE_IP + "pc/group/insertUnit/" + v + "/" + this.unitid
				console.log(url)
				let user = uni.getStorageSync("user")
				uni.request({
					header: {
						"Authorization": user.token
					},
					url: url,
					method: "POST",
					success: (res) => {
						if (res.statusCode == 500) {
							uni.showToast({
								title: "此账号无效",
								icon: "error"
							})
							return
						}
						if (res.statusCode == 200) {
							uni.showToast({
								title: "添加成功",
								icon: "success"
							})
							setTimeout((r) => {
								this.getGroups()
							}, 500)
							setTimeout((r) => {
								this.getGroups()
							}, 800)
						}
					}
				})

				this.showGroutUnit = !this.showGroutUnit
			},
			addGroupsUnit(id) {
				this.unitid = id
				this.showGroutUnit = !this.showGroutUnit
				// let url = "/pc/group/insertUnit/{unitName}/{id}"

				console.log(id)
			},
			getGroups() {
				let _this = this
				let url = BASE_IP + "pc/group/query"
				let user = uni.getStorageSync("user")
				uni.request({
					header: {
						"Authorization": user.token
					},
					url: url,
					success: (res) => {
						// _this.groups = res.data
						// uni.setStorageSync("groups", res.data)
						// console.log(res)

						if (res.statusCode == 200) {
							let g = res.data
							this.groups = g
							let groupNames = []
							for (let i in g) {
								let t = {
									name: g[i].groupsName,
									disabled: false
								}
								groupNames.push(t)
							}
							// let temp = []
							// temp.push(groupNames)
							this.groupNamesDate = []
							this.groupNamesDate = groupNames
						} else {}

					}
				})

				// console.log(groupNames)
				// uni.navigateTo({
				// 	url: "/pages/index/index",
				// 	success: (res) => {
				// 		uni.navigateBack()
				// 	}
				// })
			},
			onAddGroup() {
				if (this.groupName == "") {
					uni.showToast({
						title: "分组名未添加",
						icon: "error"
					})
					return
				}
				let t = this.groups
				for (let i in t) {
					if (t[i].groupsName == this.groupName) {
						uni.showToast({
							title: "此分组已存在",
							icon: "error"
						})
						return
					}
				}
				if (this.groupUser == "") {
					uni.showToast({
						title: "监管人员未添加",
						icon: "error"
					})
					return
				}
				let url = BASE_IP + "pc/group/insertGroup/" + this.groupName + "/" + this.groupUser
				let user = uni.getStorageSync("user")
				uni.request({
					header: {
						"Authorization": user.token
					},
					url: url,
					method: "POST",
					success: (res) => {
						if (res.statusCode == 500) {
							uni.showToast({
								title: "此账号无效",
								icon: "error"
							})
							return
						}
						if (res.statusCode == 200) {
							uni.showToast({
								title: "添加成功",
								icon: "success"
							})
							setTimeout((r) => {
								this.getGroups()
							}, 500)
							setTimeout((r) => {
								this.getGroups()
							}, 800)
						}
					}
				})
				this.showGroup = false
			},
			oSetCity(e) {
				// console.log(e)
				if (this.showDistrict == true) {
					this.unitsAdd.unitDistrict = e.areaName
				}
				if (this.showUnitsAdd_jianguan == true) {
					this.contro_group_list.unitArea = e.areaName
				}
				this.showDistrict = false
			},
			onSelectLocat() {
				uni.chooseLocation({
					isHighAccuracy: true,
					success: (res) => {
						console.log(res)
					}
				});
			},
			getServerData() {

			},
			onTabs(res) {
				this.serachVal = ''
				this.currentPage = 1
				this.noMore = false
				this.loading = false
				if (res.index == 0) {
					this.getUsers()
				}
				if (res.index == 1) {
					this.getUnit()
				}
				if (res.index == 2) {
					this.jiangunList = []
					this.getSuperviseGroup()
					// this.getGroups()
				}
				if (res.index == 3) {
					this.getAdminGroup()
					// this.queryDevices()
				}
				this.index = res.index
			},
			onShowAuthority(itme) {
				this.showAuthority = !this.showAuthority
				// console.log(itme)
				this.userItme = itme
			},
			onShowcode(itme) {
				this.modifyPwdFlag = true;

				console.log("修改密码点击事件！")
			},
			closeNewPwd() {
				this.modifyPwdFlag = false
			},
			logout() {
				let url = BASE_API + "pc/user/logout"
				let user = uni.getStorageSync("user")
				uni.request({
					header: {
						"Authorization": user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: url,
					method: "POST",

				})
				uni.clearStorageSync()
				uni.clearStorage()
				//在起始页面跳转到test.vue页面并传递参数
				//在起始页面跳转到test.vue页面并传递参数
				uni.redirectTo({
					url: 'pages/login/login'
				});
			},
			updateNewPwd() {
				if (!this.changeForm.newpwd) {
					uni.showToast({
						title: "密码不能为空",
						icon: "error"
					})
					return
				}
				// 这里需要新增一个管理员修改用户密码接口
				// let url=""
				let user = uni.getStorageSync("user")
				console.log("用户=" + JSON.stringify(user))
				let url = BASE_IP + "pc/user/update/pwd/" + user.phone + "/" + this.changeForm.newpwd
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					url: url,
					success: (res) => {
						console.log("相应结果=" + JSON.stringify(res))
						if (res.data == true) {
							this.changeForm.newpwd = ''
							uni.showToast({
								title: "修改成功",
								icon: "success"
							})
							this.logout()
						} else {
							uni.showToast({
								title: "修改失败",
								icon: "warn"
							})
						}
						let closefunc = setTimeout((res => {
							this.modifyPwdFlag = false
						}), 500)
						let time = setTimeout((res => {
							this.getUsers()
						}), 500)
					}
				})
			},
			onAuthority(res) {
				let index = 0
				if (res.indexs == 0) {
					index = 1
				} else if (res.indexs == 1) {
					index = 2
				} else if (res.indexs == 2) {
					index = 3
				}

				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/user/update/power/" + this.userItme.userName + "/" + index
				console.log(url)
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					url: url,
					success: (res) => {
						uni.showToast({
							title: "修改成功",
							icon: "success"
						})
						let time = setTimeout((res => {
							this.getUsers()
						}), 500)

						let time1 = setTimeout((res => {
							this.getUsers()
						}), 800)

					}
				})
				this.showAuthority = false
			},
			onTines(res) {
				let time = res.value
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/user/update/workTime/" + this.userItme.userName + "/" + time
				// console.log(url)
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					url: url,
					success: (res) => {
						uni.showToast({
							title: "修改成功",
							icon: "success"
						})
						let time = setTimeout((res => {
							this.getUsers()
						}), 500)

						let time1 = setTimeout((res => {
							this.getUsers()
						}), 800)
					}
				})
				this.showTime = false
			},
			onShowStatus(itme) {
				this.userItme = itme
				this.showStatus = !this.showStatus

			},
			onShowTime(itme) {
				this.showTime = !this.showTime
				this.userItme = itme
			},
			onStatus(res) {
				let index = 0
				if (res.indexs == 0) {
					index = 1
				} else if (res.indexs == 1) {
					index = 2
				} else if (res.indexs == 2) {
					index = 3
				}

				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/user/update/state/" + this.userItme.userName + "/" + index
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					url: url,
					success: (res) => {
						uni.showToast({
							title: "修改成功",
							icon: "success"
						})
						let time = setTimeout((res => {
							this.getUsers()
						}), 500)

						let time1 = setTimeout((res => {
							this.getUsers()
						}), 800)

					}
				})
				this.showStatus = !this.showStatus
			},
			onDelUser(itme) {
				if (itme.userName === "admin") {
					uni.showToast({
						title: "管理员账号不允许删除",
						icon: "error"
					})
					return
				}

				uni.showModal({
					title: "提示",
					content: "您确认要删除此用户吗",
					success: (res) => {
						if (res.cancel) {

						}
						if (res.confirm) {
							let user = uni.getStorageSync("user")
							let url = BASE_IP + "pc/user/remove/user/" + itme.uuid
							// console.log(url)
							uni.request({
								header: {
									"Authorization": user.token
								},
								method: "DELETE",
								url: url,
								success: (res) => {
									if (res.statusCode == 200) {
										uni.showToast({
											title: "删除成功",
											icon: "success"
										})
										this.getUsers()

									}
									if (res.statusCode == 404) {
										uni.showToast({
											title: "删除失败",
											icon: "error"
										})
									}
									if (res.statusCode == 500) {
										uni.showToast({
											title: "删除失败",
											icon: "error"
										})
									}
								}
							})
						}
					}
				})
			},
			getUsers() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/user/page/v2/1"
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					data: {
						"currentPage": this.currentPage,
						"pageSize": this.pageSize,
						"userName": this.serachVal
					},
					url: url,
					success: (res) => {
						console.log("人员列表：", res.data.records)
						if (res.statusCode == 200) {
							if (res.data.records.length === 0) {
								this.noMore = true
								return
							}
							this.users = [...this.users, ...res.data.records]
							if (res.data.records.length < this.pageSize) {
								this.noMore = true
							}
						}
					}
				})
			},
			getUsersSearch() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/user/page/v2/1"
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					data: {
						"currentPage": 1,
						"pageSize": 999,
						"userName": this.serachVal
					},
					url: url,
					success: (res) => {
						console.log("人员列表：", res.data.records)
						if (res.statusCode == 200) {
							this.users = res.data.records
						}
					}
				})
			},
			onSelectTime(res) {
				const dateValue = res.value
				const formattedDate = new Date(dateValue).toISOString().split("T")[0];
				console.log(formattedDate)
				this.userAdd.data = formattedDate
				this.showSelectTime = !this.showSelectTime
			},
			onUserAdd() {
				// if (this.userAdd.name == "") {
				// 	uni.showToast({
				// 		title: "账号为空",
				// 		icon: "error"
				// 	})
				// 	return
				// }
				// if (this.userAdd.name.length <= 6) {
				// 	uni.showModal({
				// 		title: "提示",
				// 		content: "请输入大于6位数的账号",
				// 		showCancel: false
				// 	})
				// 	return
				// }
				if (this.userAdd.nickName == "") {
					uni.showToast({
						title: "用户名为空",
						icon: "error"
					})
					return
				}
				if (this.userAdd.phone == "") {
					uni.showToast({
						title: "手机号为空",
						icon: "error"
					})
					return
				}
				if (this.userAdd.pwd == "") {
					uni.showToast({
						title: "密码为空",
						icon: "error"
					})
					return
				}
				if (this.userAdd.data == "") {
					uni.showToast({
						title: "过期时间为空",
						icon: "error"
					})
					return
				}
				if (this.userAdd.unit == "") {
					uni.showToast({
						title: "请绑定单位",
						icon: "error"
					})
					return
				}
				let users = this.users
				// let flag = true
				// for (let index in users) {
				// 	if (users[index].userName == this.userAdd.name) {
				// 		flag = false
				// 	}
				// }
				// if (!flag) {
				// 	uni.showToast({
				// 		title: "账号已存在",
				// 		icon: "error"
				// 	})
				// 	return
				// }

				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/user/register/" + this.userAdd.unit
				// console.log(url)
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					data: {
						password: this.userAdd.pwd,
						userExpirationTime: this.userAdd.data,
						userName: this.userAdd.phone,
						nickName: this.userAdd.nickName,
						phone: this.userAdd.phone
					},
					url: url,
					success: (res) => {
						if (res.statusCode == 200) {
							if (res.data.code != 1) {
								uni.showToast({
									title: res.data.msg,
									icon: "none"
								})
							} else {
								uni.showToast({
									title: "添加成功",
									icon: "success"
								})
								this.getUsers()
								this.showUserAdd = false
								return
							}
						}
						if (res.statusCode == 500) {
							uni.showToast({
								title: "添加失败",
								icon: "error"
							})
							return
						}
					}
				})
			},
			getUnit() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/unit/page/v2"
				uni.request({
					header: {
						"Authorization": user.token
					},
					data: {
						"currentPage": this.currentPage,
						"pageSize": this.pageSize,
						"unitName": this.serachVal,
					},
					method: "POST",
					url: url,
					success: (res) => {
						console.log("单位列表：", res.data.records)
						if (res.statusCode == 200) {
							if (res.data.records.length === 0) {
								this.noMore = true
								return
							}
							this.units = [...this.units, ...res.data.records]

							if (res.data.records.length < this.pageSize) {
								this.noMore = true
							}
						}
					}
				})
			},
			autofillHideDropdown() {
				// 如果不需要具体逻辑，可留空
				console.log('autofillHideDropdown called');
			},
			getAllUnit() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/unit/page/v2"
				uni.request({
					header: {
						"Authorization": user.token
					},
					data: {
						"currentPage": 1,
						"pageSize": 999,
					},
					method: "POST",
					url: url,
					success: (res) => {
						console.log("单位列表", res.data)
						if (res.statusCode == 200) {
							let units = res.data.records;
							let temp = [
								[]
							];
							for (let unit in units) {
								temp[0].push(units[unit].unitName);
							}
							this.unitNames = temp
						}
					}
				})

			},
			onUnit(res) {
				// this.getUnit()
				this.userAdd.unit = res.value
				this.showUnit = false
			},
			onUnits(itme) {
				if (this.units.length <= 1) {
					uni.showModal({
						title: "提示",
						content: "最后一个单位不允许删除",
						showCancel: false,
						success: (res) => {
							if (res.confirm) {
								return
							}
						}
					})
					return
				}
				uni.showModal({
					title: "提示",
					content: "您确定要删除此单位吗？此操作会同时删除所有关联的用户",
					success: (res) => {
						if (res.cancel) {}
						if (res.confirm) {

							let user = uni.getStorageSync("user")
							let url = BASE_IP + "pc/unit/" + itme.unitID
							uni.request({
								header: {
									"Authorization": user.token
								},
								method: "DELETE",
								url: url,
								success: (res) => {
									console.log("单位删除回调：", res)
									if (res.statusCode == 200) {
										uni.showToast({
											title: "删除成功",
											icon: "success"
										})
										let time = setTimeout((res => {
											this.getUnit()
										}), 500)

										let time1 = setTimeout((res => {
											this.getUnit()
										}), 800)
									}
									if (res.statusCode == 404) {
										uni.showToast({
											title: "删除失败",
											icon: "error"
										})
										return
									}
									if (res.statusCode == 500) {
										uni.showToast({
											title: "删除失败",
											icon: "error"
										})
										return
									}
								}
							})

						}
					}
				})
			},
			onUnitsAdd() {
				if (this.unitsAdd.unitName == "") {
					uni.showToast({
						title: "单位名称为空",
						icon: "error"
					})
					return
				}
				if (this.unitsAdd.safetyName == "") {
					uni.showToast({
						title: "安全责任人为空",
						icon: "error"
					})
					return
				}
				if (this.unitsAdd.safetyPhone == "") {
					uni.showToast({
						title: "联系方式为空",
						icon: "error"
					})
					return
				}
				if (this.unitsAdd.unitAddress == "") {
					uni.showToast({
						title: "单位地址为空",
						icon: "error"
					})
					return
				}
				if (this.unitsAdd.unitDistrict == "") {
					uni.showToast({
						title: "所属区域为空",
						icon: "error"
					})
					return
				}
				if (this.unitsAdd.unitNature == "") {
					uni.showToast({
						title: "企业类型为空",
						icon: "error"
					})
					return
				}
				if (this.unitsAdd.groupName == "") {
					uni.showToast({
						title: "单位分组信息为空",
						icon: "error"
					})
					return
				}
				if (this.unitsAdd.unitType == "") {
					uni.showToast({
						title: "单位经营类型为空",
						icon: "error"
					})
					return
				}
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/unit/insert"
				uni.request({
					header: {
						"Authorization": user.token
					},
					data: {
						"landPlanningType": this.unitsAdd.landPlanningType,
						"safetyName": this.unitsAdd.safetyName,
						"safetyPhone": this.unitsAdd.safetyPhone,
						"unitAbbreviation": this.unitsAdd.unitAbbreviation,
						"unitAddress": this.unitsAdd.unitAddress,
						"unitArea": this.unitsAdd.unitArea,
						"unitName": this.unitsAdd.unitName,
						"unitType": this.unitsAdd.unitType,
						"unitDistrict": this.unitsAdd.unitDistrict,
						"unitNature": this.unitsAdd.unitNature,
						"unitNatureId": this.unitsAdd.unitNatureId,
						"groupID": this.unitsAdd.groupID,
						"groupName": this.unitsAdd.groupName,
					},
					method: "POST",
					url: url,
					success: (res) => {
						if (res.statusCode == 200) {
							uni.showToast({
								title: "添加成功",
								icon: "success"
							})
							let time = setTimeout((res => {
								this.getUnit()
							}), 500)
							let time1 = setTimeout((res => {
								this.getUnit()
							}), 800)
						}
						if (res.statusCode == 500) {
							uni.showToast({
								title: "添加失败",
								icon: "error"
							})
							return
						}
						if (res.statusCode == 404) {
							uni.showToast({
								title: "添加失败",
								icon: "error"
							})
							return
						}
					}
				})
				this.showUnitsAdd = false
			},
			onUnitsAdd_jianguan() {
				if (this.contro_group_list.control_group == "") {
					uni.showToast({
						title: "监管分组名",
						icon: "error"
					})
					return
				}

				if (this.contro_group_list.unitArea == "") {
					uni.showToast({
						title: "所属区域为空",
						icon: "error"
					})
					return
				}
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/group/save/control/group"
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					data: {
						"type": "2000",
						"area": this.contro_group_list.unitArea,
						"groupName": this.contro_group_list.control_group,
					},
					url: url,
					success: (res) => {
						console.log("新增监管分组：", res.data)
						if (res.statusCode == 200) {
							uni.showToast({
								title: "添加成功",
								icon: "success"
							})
							this.jiangunList = [];
							this.createPage()
							this.loadData()
							this.showUnitsAdd_jianguan = false
						}
					}
				})

			},
			onunitNature(res) {
				console.log("企业类型选择", res)
				this.unitsAdd.unitNature = res.label
				this.unitsAdd.unitNatureId = res.value
				this.showNnitNature = false
			},
			onGroupSubmit(res) {
				console.log("分组选择", res)
				this.unitsAdd.groupName = res.groupsName
				this.unitsAdd.groupID = res.id
				this.showgroupSelect = false
			},
			onUnitType(res) {
				console.log(res)
				this.unitsAdd.unitType = res.value[0]
				this.showUnitType = false
			}, //显示下拉菜单
			assetsTap() {
				this.$refs.ddlAssets.show()
				this.assetsShow = true;
			},
			assetsItemClick(e) {
				console.log(e)
				this.assets = e.text
				this.assetsClose()
			},
			assetsClose() {
				this.assetsShow = false;
			},
			tagTap() {
				this.$refs.ddmTag.show()
				this.tagShow = true;
			},
			tagItemClick(e) {
				// console.log(e)
				this.tag = e.text

				this.unitsName = e.text
				this.unitsName += "："
				this.unitIndex = e.index
				this.tagClose()
			},
			tagClose() {
				this.tagShow = false;
			}
		}
	};
</script>

<style scoped>
	.pop-addgroups {
		width: 100%;
		height: 800rpx;
		/* background-color: goldenrod; */
	}

	.com_btn {
		background: #49A0FF;
		color: #fff;
		padding: 20rpx 0;
		font-size: 32rpx;
		border-radius: 0;
	}

	.add_user {
		position: fixed;
		right: 10rpx;
		bottom: 20%;
		border-radius: 50%;
		background: #49A0FF;
		color: #fff;
		width: 100rpx;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 999;
	}

	.charts-box {
		width: 100%;
		/* height: 300px; */
	}

	.charts-t {
		width: 100%;
		/* height: 50px; */
	}

	.charts-user {
		width: 95%;
		height: 100%;
		margin: auto;
	}

	.charts-unit {
		width: 95%;
		height: 100%;
		margin: auto;
	}

	.charts-user-list {
		width: 100%;
		height: auto;
		margin: auto;
	}

	.charts-user-list-son {
		padding-top: 10rpx;
		padding-bottom: 10rpx;
	}

	.slot-content-user-ops {
		padding-top: 20rpx;
	}

	.fui-filter__icon {
		transition: all .15s linear;
	}

	.fui-icon__ani {
		transform: rotate(180deg);
	}

	.fui-list__cell {
		width: 100%;
	}

	.fui-select {
		flex: 1;
		height: 80rpx;
		padding: 32rpx;
		box-sizing: border-box;
		position: relative;
	}

	.fui-select::after {
		content: '';
		position: absolute;
		left: 0;
		top: 0;
		width: 200%;
		height: 200%;
		border: 1px solid #eee;
		transform: scale(.5);
		transform-origin: 0 0;
		pointer-events: none;
	}

	.fui-flex__center {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.fui-flex__between {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.h100 {
		height: calc(100vh - 80px);
	}

	.list_item {
		display: flex;
		justify-content: center;
		align-items: center;
		border: 1px solid #f5f5f5;
	}

	.fui-item__box {
		width: 100%;
		padding: 26rpx 32rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.pwdModify {
		/* width: 300rpx; */
		padding: 30rpx;
		border-radius: 10rpx;
	}

	.loading,
	.no-more {
		text-align: center;
		padding: 40rpx;
		color: #999;
	}
</style>